package com.crfchina.compute.computeservice.controller;

import com.crfchina.compute.computeservice.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

@RestController
public class ComputeController {
    //private final static Logger logger = LoggerFactory.getLogger(ComputeController.class);
    @Autowired
    private DiscoveryClient client;
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public Integer add(@RequestParam Integer a,@RequestParam Integer b){
        ServiceInstance instance = client.getLocalServiceInstance();
        Integer c=a+b;
        System.out.println("/add, host:" + instance.getHost() + ", service_id:" +instance.getServiceId()+",result:"+Integer.toString(c));
        return a+b;


    }
    //服务提供者实现post方式
    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public String user(@RequestBody User user){
        ServiceInstance instance = client.getLocalServiceInstance();
        System.out.println("/user, host:" + instance.getHost() + ", service_id:" +instance.getServiceId()+",result:"+user.getName());
        return "hello:"+user.getName()+","+user.getAge();
    }
}
